﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.fountain {
    import flash.events.*;
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.models.fountain.*;

    public class HarvestSymbolCommand extends Command {

        public var symbols:SymbolModel;
        public var tree:TreeModel;
        public var user:UserModel;
        public var userModel:UserModel;

        override public function execute():void{
            var _local1:String;
            var _local2:Object;
            var _local3:Array;
            var _local4:TaskRequestEvent;
            if (this.tree.state == GameConstants.RIPE){
                this.tree.state = GameConstants.HARVESTING;
                _local1 = ("Reward" + Strings.capitalize(this.tree.symbol));
                _local2 = {taskType:GameConstants.COLLECT_ITEM, itemType:_local1, onResult:this.onHarvest};
                _local3 = [new RequestVO("harvest_tree", {id:this.user.visitingFriendID})];
                _local4 = new TaskRequestEvent(EventConstants.SEND_TASK_REQUEST, _local3, _local2);
                dispatch(_local4);
                dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_HARVEST_GEM));
            };
        }
        private function onHarvest(_arg1:ResultVO):void{
            var _local3:int;
            var _local4:Object;
            var _local5:Boolean;
            var _local6:Object;
            if (_arg1.success){
                _local4 = _arg1.data.harvest_tree;
                this.symbols.symbols = _local4.symbols;
                _local5 = (this.user.visitingFriendID == GameConstants.KARLA_FACEBOOK_ID.toString());
                if (((this.user.isVisitFriendsMode()) && (!(_local5)))){
                    _local6 = {symbol:("fountain_symbol_" + _local4.tree.symbol)};
                    dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.STOLEN_GEM_POPUP, _local6));
                };
                dispatch(new InfoEvent(EventConstants.INIT_TREE, null, _local4.tree));
            };
            dispatch(new Event(EventConstants.REMOVE_SYMBOL_FROM_FRIENDS_MENU));
            var _local2:int;
            for each (_local3 in Object(_local4.symbols)) {
                _local2 = (_local2 + _local3);
            };
            this.userModel.numberOfCollectedSymbols = _local2;
            dispatch(new Event(EventConstants.UPDATE_ACHIEVEMENTS));
        }

    }
}//package net.wooga.pets.controllers.fountain 
